/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package LDAPConn;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 *
 * @author anvil
 */
public class EmployeeTable {
    
    public static String searchTable()
    {
        String tableString="";
        
        LDAPBroker.getLDAPBroker().setConnectionDetails("localhost", 389, "dc=example,dc=com");
        LDAPBroker.getLDAPBroker().connect();
         List<Entry> atributes = LDAPBroker.getLDAPBroker().getAllEntries();
        Iterator it = atributes.iterator();
        
         while(it.hasNext()) {
            Entry e = (Entry) it.next();
            Iterator it2 = e.getAttributeValues().entrySet().iterator();
            
            //TODO CREATE A ROW
            while(it2.hasNext()) {
                Map.Entry pairs = (Map.Entry)it2.next();
                // TODO ADD VALUE TO COLUMN
                //tableString+="\tAttribute: " + pairs.getKey() + " , " + pairs.getValue());
            }
         }
        
        return tableString;
    }
    
    public static String getTableRows()
    {
        String tableRows="";
        
        LDAPBroker.getLDAPBroker().setConnectionDetails("localhost", 389, "dc=example,dc=com");
        LDAPBroker.getLDAPBroker().connect();
        List<Entry> atributes = LDAPBroker.getLDAPBroker().getAllEntries();
        Iterator it = atributes.iterator();
        
        while(it.hasNext()) 
        {
            Entry e = (Entry) it.next();
            Iterator it2 = e.getAttributeValues().entrySet().iterator();
            //TODO CREATE A ROW
            tableRows+="<tr>";
            while(it2.hasNext()) 
            {
                Map.Entry pairs = (Map.Entry)it2.next();
                tableRows+="<td>"+pairs.getValue()+"</td>";
            }
            tableRows+="</tr>";
        }
        LDAPBroker.getLDAPBroker().disconnect();
        return tableRows;
    }
    
    public static String getHeaders()
    {
        String tableString="";
        
        LDAPBroker.getLDAPBroker().setConnectionDetails("localhost", 389, "dc=example,dc=com");
        LDAPBroker.getLDAPBroker().connect();
        List<Entry> atributes = LDAPBroker.getLDAPBroker().getAllEntries();
        Iterator it = atributes.iterator();
        
        while(it.hasNext()) 
        {
            Entry e = (Entry) it.next();
            Iterator it2 = e.getAttributeValues().entrySet().iterator();
            
            
            while(it2.hasNext()) 
            {
                Map.Entry pairs = (Map.Entry)it2.next();
                tableString+="<th>"+pairs.getKey()+"</th>";
            }
            break;
        }
    LDAPBroker.getLDAPBroker().disconnect();
    return tableString;
    }
}
